import { createRouter, createWebHistory } from 'vue-router';
import { useLoginStore } from '@/store/login';
const router = createRouter({
    history:createWebHistory(),
    routes:[
        // { path: '/:path(.*)', redirect: '/' },
        {
            path:'/home',
            name:'home',
            component:()=>import('@/views/Home.vue'),
        },
        {
            path: '/article/:id',
            name: 'ArticleDetail',
            component: ()=>import('@/views/administor/ArticleDetail.vue')
        },
        {
            path:'/articlesManage',
            name:'articlesManage',
            component:()=>import('@/views/administor/ArticleManage.vue')
        },
        {
            path:'/labelManage',
            name:'labelManage',
            component:()=>import('@/views/administor/LabelManage.vue')
        },
        {
            path:'/userManage',
            name:'userManage',
            component:()=>import('@/views/administor/UserManage.vue')
        },
        {
            path:'/publishArticle',
            name:'publishArticle',
            component:()=>import('@/views/publishArticle/PublishArticle.vue'),
            children:[
                {
                    path:'markDownEditor',
                    name:'markDownEditor',
                    component:()=>import('@/views/publishArticle/MarkDownEditor.vue')
                },
                {
                    path:'richTextEditor',
                    name:'richTextEditor',
                    component:()=>import('@/views/publishArticle/RichTextEditor.vue')
                },
                {
                    path:'/publishArticle',
                    redirect:'/publishArticle/markDownEditor'
                }
            ]
        },
        {
            path:'/followList',
            name:'followList',
            component:()=>import('@/views/FollowList.vue')
        },
        {
            path:'/creatorCenter',
            name:'creatorCenter',
            component:()=>import('@/views/creatorCenter/CreatorCenter.vue'),
            children:[
                {
                    path:'accountSetting',
                    name:'accountSetting',
                    component:()=>import('@/views/creatorCenter/AccountSetting.vue')
                },
                {
                    path:'articleManage',
                    name:'articleManage',
                    component:()=>import('@/views/creatorCenter/ArticleManage.vue')
                },
                {
                    path:'personalData',
                    name:'personalData',
                    component:()=>import('@/views/creatorCenter/PersonalData.vue')
                },
                {
                    path:'commentManage',
                    name:'commentManage',
                    component:()=>import('@/views/creatorCenter/CommentManage.vue')
                },{
                    path:'/creatorCenter',
                    redirect:'/creatorCenter/articleManage'
                }
            ]
        },
    ]
})
router.beforeEach((to, from, next) => {
  if (to.path === '/') {
    const loginStore = useLoginStore();
    if (loginStore.userLevel === '1') {
        next('/userManage');
    } else {
        next('/home');
    }
  } else {
    next();
  }
});
export default router;